Skip to content

Conversation

@hadley
Copy link
Member

@hadley hadley commented Aug 4, 2025

Using the digits calculation from waldo, displaying the actual calculation, comparison, and renaming "more" to "greater"

Fixes #2006

@MichaelChirico could you please take a look? This doesn't need to be perfect, but is hopefully better than the current display.

hadley added 2 commits August 4, 2025 16:31
Using the digits calculation from waldo, displaying the actual calculation, comparison, and renaming "more" to "greater"

Fixes #2006
">=" = "not greater than"
)[[operator]]

negated_op <- switch(operator, "<" = ">", "<=" = ">=", ">" = "<", ">=" = "<=")
Copy link
Contributor

@MichaelChirico MichaelChirico Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these wrong? e.g. I think we'll get

expect_snapshot_failure(expect_gt(x, 1.0 * x))
    `x` is not strictly greater than 1.0 * x.
    0.0000100 - 0.0000110 = 0 < 0

The negated open interval is a closed interval, and vice versa.

https://github.com/r-lib/lintr/blob/84d3f8c5f4b3576defe880872ec413df8986ef9c/R/comparison_negation_linter.R#L40

(even if I'm reading it wrong we'll still want a test of the edge case)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, yes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also that revealed a bug when the number of digits in the difference is much smaller than the values.

Copy link
Contributor

@MichaelChirico MichaelChirico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, output LGTM! It might be helpful to add another example where the values are totally different just to get a glimpse of what that will look like.

@hadley hadley merged commit a7983dd into main Aug 5, 2025
10 of 11 checks passed
@hadley hadley deleted the comparison-display branch August 5, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expect_comparison could use waldo to determine digits in the failure case?

3 participants